package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.DTRequestDto;
import com.hualude.roadsign.dto.DTResponseDto;
import com.hualude.roadsign.dto.JsonMsgDto;
import com.hualude.roadsign.service.GuardrailFaultService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by pjn on 2017/8/15.
 */
@Controller
@RequestMapping("/rds_guardrailFault")
public class GuardrailFaultController {
    @Resource
    private GuardrailFaultService guardrailFaultService;

    @RequestMapping(value = "/getGuardrailReportFault4DT")
    @ResponseBody
    public DTResponseDto getGuardrailReportFault4DT(DTRequestDto dtRequestDto, Integer actorId, Integer userId, Integer orgId) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = guardrailFaultService.getGuardrailReportFault4DT(dtRequestDto, actorId, userId, orgId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping("/updateGuardrailFault")
    @ResponseBody
    public JsonMsgDto updateGuardrailFault(Integer guardrailFaultId, Integer guardrailFaultLevel, Integer guardrailFaultType, String guardrailFaultPhoto, String guardrailFaultReason, Double guardrailMoney) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(guardrailFaultService.updateGuardrailFault(guardrailFaultId, guardrailFaultLevel, guardrailFaultType, guardrailFaultPhoto, guardrailFaultReason, guardrailMoney));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);

        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/deleteGuardrailFaultByIds")
    @ResponseBody
    public JsonMsgDto deleteGuardrailFaultByIds(String guardrailFaultIds) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(guardrailFaultService.deleteGuardrailFaultByIds(guardrailFaultIds));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }



    @RequestMapping(value = "/reportGuardrailFault")
    @ResponseBody
    public JsonMsgDto reportGuardrailFault(Integer guardrailId, Integer guardrailFaultCreatorId, Integer guardrailFaultLevel, Integer guardrailFaultType,
                                         String guardrailFaultPhoto, String guardrailFaultReason, Double guardrailMoney, Integer guardrailOrgId, Integer guardrailMainOrgId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            guardrailFaultService.reportGuardrailFault(guardrailId, guardrailFaultCreatorId, guardrailFaultLevel, guardrailFaultType,
                    guardrailFaultPhoto, guardrailFaultReason, guardrailMoney, guardrailOrgId, guardrailMainOrgId);
            //为空是app端作判断
            jsonMsgDto.setJsonData("");
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getGuardrailFaultIsReport")
    @ResponseBody
    public JsonMsgDto getGuardrailFaultIsReport(Integer guardrailId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(guardrailFaultService.getGuardrailFaultIsReport(guardrailId));
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getGuardrailFaultReport4DT")
    @ResponseBody
    public DTResponseDto getGuardrailFaultReport4DT(DTRequestDto dtRequestDto, Integer actorId, Integer orgId,String roadName, String startRoad, String endRoad) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = guardrailFaultService.getGuardrailFaultReport4DT(dtRequestDto, actorId, orgId, roadName, startRoad, endRoad);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping("/getStartRoad")
    @ResponseBody
    public JsonMsgDto getStartRoad(String roadName, Integer actorId, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(guardrailFaultService.getStartRoad(roadName, actorId, orgId));
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getSectionByStartRoad")
    @ResponseBody
    public JsonMsgDto getSectionByStartRoad(String roadName, Integer actorId, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(guardrailFaultService.getSectionByStartRoad(roadName,actorId, orgId));
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getGuardrailFaultList4App")
    @ResponseBody
    public JsonMsgDto getGuardrailFaultList4App(Integer orgId, String actorIds, Integer faultStatus, Integer count, Integer size)
            throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(guardrailFaultService.getGuardrailFaultList4App(orgId,actorIds,faultStatus,count,size));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getGuardrailCoordinates4AppMap")
    @ResponseBody
    public JsonMsgDto getGuardrailCoordinates4AppMap(Integer orgId, Integer orgType, Integer actorId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(guardrailFaultService.getGuardrailCoordinates4Map(orgId, orgType, actorId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

}
